package com.yuneec.fly;

import android.app.FragmentManager;

import com.yuneec.fly.events.EventBusFactory;
import com.yuneec.fly.events.uiEvent.MissionStatusChangeEvent;
import com.yuneec.fly.events.uiEvent.SetFenceMarkerDraggableEvent;
import com.yuneec.fly.events.uiEvent.SwitchMapActionEvent;
import com.yuneec.fly.models.DroneTypeFactory;
import com.yuneec.fly.utils.LocationConverter;
import com.yuneec.fly.utils.LocationUtils;
import com.yuneec.droneservice.model.ControllerLocation;
import com.yuneec.droneservice.parse.DroneFeedback;

import java.util.ArrayList;

/**
 * Created by jw.gu on 2016/6/14.
 */
public class GlobalParams {
    public static boolean addingPoint = false;
    public static boolean addingPoints = false;
    public static boolean addingInterest = false;
    public static boolean addingFence = false;
    public static boolean selectingLandPoint = false;
    public static DroneFeedback droneFeedback = null;
    public static DroneTypeFactory.DroneType droneType = null;
    public static int velocityUnit = LocationUtils.UNIT_METRIC;
    public static ViewStatus videoViewStatus = ViewStatus.MINI;
    public static ViewStatus mapViewStatus = ViewStatus.MAX;
    public static boolean hasPutGeofence = false;
    public static boolean isPutGestureGeofenceEnd = true;
    public static boolean droneConnected = false;
    public static FragmentManager fragmentManager = null;
    public static boolean droneFlying = false;
    public static boolean droneLocked = true;
    private static MissionStatus missionStatus = MissionStatus.NONE;
    public static int currentWaypointIndex = 0;//start from 1
    public static int waypointStartIndex = 0;//start from 0
    public static boolean needReconnectCamera = false;
    public static boolean sIsStartWayPointFromSelectedIndex = false;
    public static int sCurrentWayPointUserIndex = 1;//start from 1
    public static byte fenceType;
    public static long lastDroneFeedbackTime;
    public static LocationConverter.LatLng landLatLng;
    public static boolean updating = false;

    public static final int HW_INDEX_BASE_B = 50;
    public static final int CAMERA_KEY_INDEX = HW_INDEX_BASE_B + 3;
    public static final int VIDEO_KEY_INDEX = HW_INDEX_BASE_B + 4;

    public static MissionStatus getMissionStaus() {
        return missionStatus;
    }

    public static int sCurrentPOIArrayIndex = 0;
    public static CameraType cameraType = null;
    public static String language = null;
    public static String videoPath;
    public static String connectedCamera;
    public static boolean stopAllCommand;

    public static void setMissionStaus(MissionStatus status) {
        if (status == MissionStatus.NONE && (missionStatus == MissionStatus.FENCE_RUNNING
                || missionStatus == MissionStatus.FENCE_PAUSE)) {
            EventBusFactory.getUiBus().post(new SwitchMapActionEvent(SwitchMapActionEvent.ActionType.HIDE));
            EventBusFactory.getUiBus().post(new SetFenceMarkerDraggableEvent(true));
        }
        if ((status == MissionStatus.FENCE_RUNNING || status == MissionStatus.FENCE_PAUSE) && missionStatus == MissionStatus.NONE) {
            EventBusFactory.getUiBus().post(new SetFenceMarkerDraggableEvent(false));
        }
        missionStatus = status;
        if (status != MissionStatus.WAYPOINT_PAUSE && status != MissionStatus.WAYPOINT_RUNNING) {
            currentWaypointIndex = 0;
            waypointStartIndex = 0;
        }
        EventBusFactory.getUiBus().post(new MissionStatusChangeEvent());
    }


    public static ArrayList<String> savedRouteNames = new ArrayList<>();

    public static void exit() {
        addingPoint = false;
        addingPoints = false;
        addingFence = false;
        addingInterest = false;
        selectingLandPoint = false;
        droneFeedback = null;
        droneType = null;
        velocityUnit = LocationUtils.UNIT_METRIC;
        videoViewStatus = ViewStatus.MINI;
        mapViewStatus = ViewStatus.MAX;
        droneConnected = false;
        fragmentManager = null;
        droneFlying = false;
        droneLocked = true;
        missionStatus = MissionStatus.NONE;
        currentWaypointIndex = 0;
        waypointStartIndex = 0;
        needReconnectCamera = false;
        sIsStartWayPointFromSelectedIndex = false;
        sCurrentWayPointUserIndex = 1;
        fenceType = 0;
        sCurrentPOIArrayIndex = 0;
        lastDroneFeedbackTime = 0;
        landLatLng = null;
        cameraType = null;
        savedRouteNames.clear();
        language = null;
        connectedCamera = null;
        resetGeofence();
        updating = false;
    }

    public static void resetGeofence() {
    }

    public enum ViewStatus {MIN, MINI, MAX}

    public enum MissionStatus {NONE, WAYPOINT_RUNNING, WAYPOINT_PAUSE, FENCE_RUNNING, FENCE_PAUSE, LAND_RUNNING, TAKEOFF_RUNNING}

    public enum MapProvider {AMAP, GMAP}

    public static MapProvider mapProvider;

    public enum CameraType {
        CGO3, CGO3P, CGO4, CGOET, CGOPRO, FIREBIRD
    }
}
